package labmanager.database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import labmanager.utils.AccessDB;
import org.apache.log4j.Logger;

public class LabManagerTypeReservation {

	public static AccessDB mysql = new AccessDB();
	private static Logger logger = Logger.getLogger(LabManagerUser.class.getName());

	public ArrayList<String> listTypeReservation(String where) {
		logger.debug(new StringBuilder("Invocando al metodo :: listTypeReservation :: Parametros recibidos: where: ")
				.append(where).toString());
		ArrayList<String> al = new ArrayList<String>();
		try {
			al.add("98");
			al.add("No se ha podido listar los tipos de reservas.");
			StringBuilder query = new StringBuilder("SELECT id, type, description FROM types_reservations WHERE ")
					.append(where).append(";");
			ResultSet result = mysql.executeQuery(query.toString());
			if (result.first()) {
				al.clear();
				StringBuilder typeReservation = new StringBuilder().append(result.getInt("id")).append("@#")
						.append(result.getString("type")).append("@#").append(result.getString("description"));
				al.add(typeReservation.toString());
				while (result.next()) {
					typeReservation = new StringBuilder().append(result.getInt("id")).append("@#")
							.append(result.getString("type")).append("@#").append(result.getString("description"));
					al.add(typeReservation.toString());
				}
			} else {
				al.add("97");
				al.add("No existen tipos de reservas en base.");
			}
			result.close();
			logger.debug(new StringBuilder("Respuesta al portal:").append(al.toString()).toString());
			return al;
		} catch (SQLException e) {
			logger.debug(new StringBuilder("Se produjo un error en database/LabManagerTypeReservation al listar los tipos de reservas de la base de datos. ")
					.append(e).toString(), e);
			al.add("99");
			al.add("Se ha producido un error.");
			return al;
		}
	}

}
